package bma.common.langutil.log;

import org.slf4j.Logger;

/**
 * 日志输出对象
 * 
 * @author 关中
 * @since 1.0 (imported from BMA.ESP Project)
 * 
 */
public class LogPrinter {

	public static enum LEVEL {
		TRACE, DEBUG, INFO, WARN, ERROR
	}

	protected Logger log;
	protected LEVEL level;

	public LogPrinter() {
		super();
	}

	public LogPrinter(Logger log, LEVEL level) {
		super();
		this.log = log;
		this.level = level;
	}

	public Logger getLog() {
		return log;
	}

	public void setLog(Logger log) {
		this.log = log;
	}

	public LEVEL getLevel() {
		return level;
	}

	public void setLevel(LEVEL level) {
		this.level = level;
	}

	public boolean isEnabled() {
		switch (level) {
		case TRACE:
			return log.isTraceEnabled();
		case DEBUG:
			return log.isDebugEnabled();
		case INFO:
			return log.isInfoEnabled();
		case WARN:
			return log.isWarnEnabled();
		case ERROR:
			return log.isErrorEnabled();
		default:
			return false;
		}
	}

	public void print(String msg) {
		switch (level) {
		case TRACE:
			log.trace(msg);
			break;
		case DEBUG:
			log.debug(msg);
			break;
		case INFO:
			log.info(msg);
			break;
		case WARN:
			log.warn(msg);
			break;
		case ERROR:
			log.error(msg);
			break;
		default:
			break;
		}
	}

	public void print(String format, Object arg) {
		switch (level) {
		case TRACE:
			log.trace(format, arg);
			break;
		case DEBUG:
			log.debug(format, arg);
			break;
		case INFO:
			log.info(format, arg);
			break;
		case WARN:
			log.warn(format, arg);
			break;
		case ERROR:
			log.error(format, arg);
			break;
		default:
			break;
		}
	}

	public void print(String format, Object arg1, Object arg2) {
		switch (level) {
		case TRACE:
			log.trace(format, arg1, arg2);
			break;
		case DEBUG:
			log.debug(format, arg1, arg2);
			break;
		case INFO:
			log.info(format, arg1, arg2);
			break;
		case WARN:
			log.warn(format, arg1, arg2);
			break;
		case ERROR:
			log.error(format, arg1, arg2);
			break;
		default:
			break;
		}
	}

	public void print(String format, Object[] argArray) {
		switch (level) {
		case TRACE:
			log.trace(format, argArray);
			break;
		case DEBUG:
			log.debug(format, argArray);
			break;
		case INFO:
			log.info(format, argArray);
			break;
		case WARN:
			log.warn(format, argArray);
			break;
		case ERROR:
			log.error(format, argArray);
			break;
		default:
			break;
		}
	}

	public void debug(String msg, Throwable t) {
		switch (level) {
		case TRACE:
			log.trace(msg, t);
			break;
		case DEBUG:
			log.debug(msg, t);
			break;
		case INFO:
			log.info(msg, t);
			break;
		case WARN:
			log.warn(msg, t);
			break;
		case ERROR:
			log.error(msg, t);
			break;
		default:
			break;
		}
	}

}
